package com.ysxsoft.wdg.adapter.center_st;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.ysxsoft.wdg.R;
import com.ysxsoft.wdg.bean.cart.ShopcartBean;
import com.ysxsoft.wdg.bean.response.StOrderResponse;
import com.ysxsoft.wdg.util.ViewUtils;

import java.util.List;

public class StOrderInnerAdapter extends RecyclerView.Adapter<StOrderInnerAdapter.MyPiHolder> {

    private List<StOrderResponse.DataBean.DetailBean> list;
    private Context mContext;

    public StOrderInnerAdapter(List<StOrderResponse.DataBean.DetailBean> list, Context mContext) {
        this.list = list;
        this.mContext = mContext;
    }

    @NonNull
    @Override
    public StOrderInnerAdapter.MyPiHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_order_inner, parent, false);//解决宽度不能铺满
        MyPiHolder holder = new MyPiHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyPiHolder holder, int position) {
        StOrderResponse.DataBean.DetailBean item = list.get(position);


        Glide.with(mContext).load(item.getPic()).into(holder.ivGoods);


        holder.tvName.setText(item.getName());
        holder.tvMoney.setText(mContext.getString(R.string.price_rmb, item.getPrice() + ""));
//        holder.tvOldMoney.setText(mContext.getString(R.string.price_rmb,item.getPrice()));
        holder.tvNum.setText("x" + item.getNum());
        holder.icon.setVisibility(View.GONE);
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    class MyPiHolder extends RecyclerView.ViewHolder{

        private ImageView ivGoods;
        private ImageView icon;
        private TextView tvName,tvMoney,tvOldMoney,tvRules,tvJf,tvNum;
        public MyPiHolder(View itemView) {
            super(itemView);

            ivGoods= itemView.findViewById(R.id.iv_pic);
            tvName = itemView.findViewById(R.id.tv_name);
            tvMoney = itemView.findViewById(R.id.tv_money);
            tvOldMoney = itemView.findViewById(R.id.tv_old_money);
            ViewUtils.setDeletLine(tvOldMoney);
            tvRules = itemView.findViewById(R.id.tv_rules);
            tvJf = itemView.findViewById(R.id.tv_jf);
            tvNum = itemView.findViewById(R.id.tv_num);
            icon = itemView.findViewById(R.id.icon);
        }
    }
}
